package com.exigen.performance.test.webapp.dao;

import java.util.List;

import javax.persistence.Query;

import com.exigen.performance.test.webapp.domain.ProjectEntity;
import com.exigen.performance.test.webapp.domain.base.GenericJPADAO;

/**
 * Class that collects project entity data from database.
 * 
 * @author Maksim Savchuk
 * 
 */
public class ProjectJpaDao extends GenericJPADAO<ProjectEntity, Long> implements
		ProjectDao {

	private final String query1 = "select distinct p from ProjectEntity p, DashboardEntity d where p.id = d.projectId";
	private final String query2 = "select distinct p from ProjectEntity p, DashboardEntity d where p.id not in (select dp.projectId from DashboardEntity dp)";

	public ProjectJpaDao() {
		super(ProjectEntity.class);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.exigen.performance.test.webapp.dao.ProjectDao#getDashboardProjects()
	 */
	public List<ProjectEntity> getDashboardProjects() {
		Query query = getEntityManager().createQuery(query1);
		@SuppressWarnings("unchecked")
		List<ProjectEntity> result = query.getResultList();
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.exigen.performance.test.webapp.dao.ProjectDao#getProjectsNotInDashboard
	 * ()
	 */
	public List<ProjectEntity> getProjectsNotInDashboard() {
		Query query = getEntityManager().createQuery(query2);
		@SuppressWarnings("unchecked")
		List<ProjectEntity> result = query.getResultList();
		return result;
	}

}
